package com.cy.aircompressor.main.home.lifecycle.detail;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.WindowManager;

import androidx.fragment.app.FragmentManager;

import com.cy.aircompressor.config.AirConfig;
import com.cy.aircompressor.databinding.DialogAircompressorDetailLayoutBinding;
import com.cy.aircompressor.entity.compressor.Compressor;
import com.jakewharton.rxbinding2.view.RxView;
import com.net.model.base.fragment.BaseVBDialogFragment;

import java.util.concurrent.TimeUnit;

public class AirCompressorDetailDialog extends BaseVBDialogFragment<DialogAircompressorDetailLayoutBinding> {
    private Compressor compressor;

    public static void showDialogFragment(FragmentManager fragmentManager, String tag, Compressor compressor) {
        Bundle args = new Bundle();
        AirCompressorDetailDialog fragment = new AirCompressorDetailDialog();
        args.putSerializable("compressor", compressor);
        fragment.setArguments(args);
        fragment.show(fragmentManager, tag);
    }

    @Override
    protected DialogAircompressorDetailLayoutBinding getViewBinding() {
        return DialogAircompressorDetailLayoutBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initData() {
        compressor = (Compressor) getArguments().getSerializable("compressor");
        mBinding.id.setText(compressor.getSn());
        mBinding.name.setText(compressor.getName());
        mBinding.brand.setText(compressor.getBrand());
        mBinding.model.setText(compressor.getModel());
        mBinding.powerStationName.setText(compressor.getPowerStationName());
        mBinding.installLocation.setText(compressor.getInstallLocation());
        mBinding.installDate.setText(compressor.getInstallDate());
        mBinding.nextMaintenanceDate.setText(compressor.getNextMaintenanceDate());
        mBinding.createTime.setText(compressor.getCreateTime());
        mBinding.updateTime.setText(compressor.getUpdateTime());
        mBinding.remark.setText(TextUtils.isEmpty(compressor.getRemark()) ? "无备注" : compressor.getRemark());
        RxView.clicks(mBinding.closeBtn)
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(o -> {
                    dismiss();
                });
    }

    @Override
    protected void requestNetwork() {

    }

    @Override
    protected int getWindowHeight() {
        return WindowManager.LayoutParams.WRAP_CONTENT;
    }

    @Override
    protected int getWindowWidth() {
        return getScreenWidth() *2/ 5;
    }

    @Override
    protected void initialize() {

    }

}
